package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class 最大和 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       final static int N=10010;
       static int f[]=new int[N],a[]=new int[N],primers[]=new int[N],cnt,n;
       static boolean st[]=new boolean[N];
       static int min_primer(int x){
    	      if(!st[x])return x;
    	      for(int i=2;i<=x/i;i++)
    	    	  if(x%i==0)
    	    		  return i;
    	      return 1;
    	      
       }
       public static void main(String[] ss) throws NumberFormatException, IOException {
		      n=Integer.parseInt(br.readLine());
		      ss=br.readLine().split(" ");
		      for(int i=1;i<=n;i++)
		    	  a[i]=Integer.parseInt(ss[i-1]);
		      st[1]=true;
		      for(int i=2;i<=10000;i++){
		    	  if(!st[i])primers[cnt++]=i;
		    	  for(int j=0;primers[j]<=10000/i;j++){
		    		  st[primers[j]*i]=true;
		    		  if(i%primers[j]==0)break;
		    	  }
		      }
		      Arrays.fill(f,-0x3f3f3f3f);
		      f[1]=a[1];
		      for(int i=1;i<=n;i++){
		    	  int d=min_primer(n-i);
		    	  for(int j=i+1;j<=i+d;j++){
		    		  f[j]=Math.max(f[j],f[i]+a[j]);
		    	  }
		      }
		      System.out.print(f[n]);
	}
}
